package org.dromara.web.websocket;

import org.apache.commons.collections4.CollectionUtils;
import org.dromara.common.json.fastjson.Fastjson;
import org.dromara.common.json.utils.JsonUtils;
import org.dromara.websocket.connection.Connection;

import java.util.List;

/**
 * Created by       PokerFace
 * Create Date      2023-09-28
 * Email:
 * Version          1.0.0
 * <p>
 * Description:
 */
public abstract class ConnectionHolder {



    abstract void onConnectionRemoved(Connection connection);



    public void push(List<Connection> connectionList, Payload payload) {
        if (CollectionUtils.isNotEmpty(connectionList)) {
            connectionList.stream().forEach(connection -> {
                push(connection, payload);
            });
        }
    }

    public void push(Connection connection, Payload payload) {
        connection.push(Fastjson.format(payload));
    }
}
